#!/bin/sh

RAILS_ENV=`/usr/local/ec2onrails/bin/rails_env`

if [ -x /mnt/app/current ] ; then
  logfile=/mnt/app/current/log/$RAILS_ENV.log-`date +%Y%m%d`
  if [ -e $logfile ] ; then
    gzip -c $logfile > $logfile.gz
    /usr/local/ec2onrails/bin/archive_file --file $logfile.gz --dir logs/rails && rm $logfile.gz
  fi
fi

if [ -e /mnt/log/nginx/access.log ] ; then
  for f in `ls /mnt/log/nginx/*.log` ; do
    logfile=$f-`date +%Y%m%d`
    if [ -e $logfile ] ; then
      gzip -c $logfile > $logfile.gz
      /usr/local/ec2onrails/bin/archive_file --file $logfile.gz --dir logs/nginx && rm $logfile.gz
    fi
  done
fi

logfile=/mnt/log/varnish/varnishncsa.log-`date +%Y%m%d`
if [ -e $logfile ] ; then
  gzip -c $logfile > $logfile.gz
  /usr/local/ec2onrails/bin/archive_file --file $logfile.gz --dir logs/varnish && rm $logfile.gz
fi

logfile=/mnt/log/god/god.log-`date +%Y%m%d`
if [ -e $logfile ] ; then
  gzip -c $logfile > $logfile.gz
  /usr/local/ec2onrails/bin/archive_file --file $logfile.gz --dir logs/god && rm $logfile.gz
fi
